home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LIFER__
/
PROTO
/
P
/
PUTILS_L.C
< prev
next >
Wrap
Text File
|
1991-07-23
|
8KB
|
205 lines
/* PUtils_Life Utilities
File name: PUtils_Life.C
Function: Utilities for the Prototyper specific code.
History: 7/23/91 Original by Prototyper 3.0 */
#include "PCommonLife.h" /* Common */
#include "Common_Life.h" /* Common */
#include "PUtils_Life.h" /* This file */
/* ======================================================= */
/* Routine: TrapAvailable */
/* Purpose: See if trap is available, non-available traps all have a unique address */
Boolean TrapAvailable (trapNumber,tType) /* See if a trap is available */
short trapNumber;
short tType;
{
#define UnimplementedTrapNumber 0xA89F /* Unimplemented trap number */
Boolean theResult;
theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));/* Check the two traps */
return(theResult);
}
/* ======================================================= */
/* Routine: GetUserEvent */
/* Purpose: See if any user events are available */
void GetUserEvent(UserEventPRec TheUserEvent)
{
UserEventHRec NextUserEvent; /* The next user event */
TheUserEvent->ID = UserEvent_None; /* Set ID to no events are available */
if (UserEventList != NIL) /* Get first entry in the list */
{
HLock((Handle)UserEventList); /* Lock for safety */
TheUserEvent->ID = (*UserEventList)->ID; /* The event ID */
TheUserEvent->ID2 = (*UserEventList)->ID2; /* The optional ID */
TheUserEvent->Data1 = (*UserEventList)->Data1;/* The optional data */
TheUserEvent->Data2 = (*UserEventList)->Data2;/* The optional data */
TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
NextUserEvent = (*UserEventList)->Next; /* The next list */
DisposHandle((Handle)UserEventList); /* Remove this list item */
UserEventList = NextUserEvent; /* Make the next item the new first item */
}
}
/* ======================================================= */
/* Routine: Add_UserEvent */
/* Purpose: Add a user event */
void Add_UserEvent( ID, ID2, Data1, Data2, theHandle)
short ID;
short ID2;
long Data1;
long Data2;
Handle theHandle;
{
UserEventHRec NewUserEvent; /* The new user event */
UserEventHRec theUserEvent; /* The user event */
NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
if (NewUserEvent != NIL) /* Only do if we got the new record */
{
HLock((Handle)NewUserEvent); /* Lock for safety */
(*NewUserEvent)->ID = ID; /* The event ID */
(*NewUserEvent)->ID2 = ID2; /* The optional ID */
(*NewUserEvent)->Data1 = Data1; /* The optional data */
(*NewUserEvent)->Data2 = Data2; /* The optional data */
(*NewUserEvent)->theHandle = theHandle; /* The optional handle */
(*NewUserEvent)->Next = NIL; /* No next item after this one */
if (UserEventList == NIL) /* See if anyone is in the list yet */
UserEventList = NewUserEvent; /* Make this one the first in the list */
else /* Not the first in the list */
{
theUserEvent = UserEventList; /* Get the first one */
while ((*theUserEvent)->Next != NIL) /* Get the next one */
{
theUserEvent = (*theUserEvent)->Next;
}
(*theUserEvent)->Next = NewUserEvent; /* Tack on to the end */
}
}
}
/* ======================================================= */
/* This is a routine used to get a string from a TE area, limited to 250 characters */
void Get_TE_String( theTEArea, theString)
TEHandle theTEArea;
Str255 *theString;
{
short Index; /* Use to loop thru the characters */
short TitleLength; /* Number of characters to do */
CharsHandle theCharsHandle; /* Used to get global edit text */
Ptr theStringPtr; /* Pointer to the string, byte level */
theCharsHandle = TEGetText(theTEArea); /* Get the character handle */
HLock((Handle)theCharsHandle); /* Lock it for safety */
TitleLength = (*theTEArea)->teLength; /* Get the number of characters */
*theString[0] = 0; /* Start with an empty string */
if (TitleLength > 0)
{
theStringPtr = (Ptr)((long)theString + (long)1); /* Start of the string data */
if (TitleLength > 250)
TitleLength = 250;
for (Index = 0; Index < TitleLength; Index++)
*theStringPtr++ = (char)(*theCharsHandle)[Index];
*theString[0] = TitleLength;
}
}
/* ======================================================= */
/* This is a routine used to create a TE area */
void Make_TE_Area(theTEArea, Position, theFontSize, theFont, DefaultStringID)
TEHandle *theTEArea;
Rect *Position;
short theFontSize;
short theFont;
short DefaultStringID;
{
FontInfo ThisFontInfo; /* Use to get the font data */
TextSize(theFontSize); /* Set the size */
TextFont(theFont); /* Set the font */
GetFontInfo(&ThisFontInfo); /* Get Ascent height for positioning */
TextSize(12); /* Restore the size */
TextFont(applFont); /* Restore the font */
tempRect = *Position; /* Get the rect */
FrameRect(&tempRect); /* Frame this TE area */
InsetRect(&tempRect, 3, 3); /* Indent for TE inside of box */
*theTEArea = TENew(&tempRect, &tempRect); /* Create the TE area */
if (theInput != NIL) /* See if there is already a TE area */
TEDeactivate(theInput); /* Yes, so turn it off */
theInput = *theTEArea; /* Activate the TE area */
HLock((Handle)*theTEArea); /* Lock the handle before using it */
(**theTEArea)->txFont = theFont; /* Font to use for the TE area */
(**theTEArea)->fontAscent = ThisFontInfo.ascent; /* Font ascent */
(**theTEArea)->lineHeight = ThisFontInfo.ascent + ThisFontInfo.descent + ThisFontInfo.leading;/* Font ascent + descent + leading */
HUnlock((Handle)*theTEArea); /* UnLock the handle when done */
GetIndString(sTemp, DefaultStringID, 1); /* Get the default string */
TESetText(&sTemp[1], sTemp[0], theInput); /* Place default text in the TE area */
TEActivate(theInput); /* Make the TE area active */
}
/* ======================================================= */
/* Setup a dialog or alert item */
void SetupTheItem( theDialog, ItemID, SizeIt, ShowIt,EnableIt,SetTheMax,thePosition, ExtraData, StringID)
DialogPtr theDialog;
short ItemID;
Boolean SizeIt;
Boolean ShowIt;
Boolean EnableIt;
Boolean SetTheMax;
Rect *thePosition;
long ExtraData;
short StringID;
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
CItem = (ControlHandle)DItem; /* Change to control handle */
if (SizeIt) /* Have to resize all CDEF connected controls */
SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
*thePosition = tempRect; /* Pass back the zone location and size */
if (ExtraData != NIL) /* See if extra data for a CDEF */
(*CItem)->contrlData = (Handle)ExtraData; /* Send it */
if (StringID != 0) /* See if a CDEF and needs the title set again*/
{
GetIndString(sTemp,StringID,1); /* Get the string */
SetCTitle(CItem,sTemp); /* Set the string */
}
if (EnableIt) /* See if enable or disable the zone */
HiliteControl (CItem,0); /* Enable the zone */
else
HiliteControl (CItem,255); /* Dim the zone */
if (SetTheMax)
SetCtlMax(CItem,12345); /* Set the flag to the CDEF */
if (ShowIt)
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */